package com.liuxinlong.modules.material.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.material.controller.request.QueryMaterialResumeReq;
import com.liuxinlong.modules.material.service.MaterialResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 物料履历信息控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2021-01-17
 */
@RestController
@RequestMapping("/material/resume")
public class MaterialResumeController {
    @Autowired
    private MaterialResumeService materialResumeService;

    /**
     * 分页查询物料履历信息
     *
     * @param req 请求信息
     * @return 物料履历信息列表
     */
    @PostMapping("page")
//    @LogAnnotation(value = "分页查询", business = LogBusinessConstants.MATERIAL_RESUME, operateType = LogOperateConstants.OPERATE_QUERY)
    public BaseResp pageResumeInfo(@RequestBody QueryMaterialResumeReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        List<Map<String, Object>> dataList = materialResumeService.pageResumeInfo(queryMap);
        int totalNum = materialResumeService.getResumeCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询物料履历信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 查询物料履历信息
     *
     * @param req 请求信息
     * @return 物料履历信息
     */
    @PostMapping("query")
    @LogAnnotation(value = "查询物料履历信息", business = LogBusinessConstants.MATERIAL_RESUME, operateType = LogOperateConstants.OPERATE_QUERY)
    public BaseResp queryResumeInfo(@RequestBody QueryMaterialResumeReq req) {
        Map<String, Object> dataMap = materialResumeService.queryResumeInfo(req.getMaterial(), req.getRegion(), req.getStartTime());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询物料履历信息成功");
        resp.setDataMap(dataMap);
        return resp;
    }

    /**
     * 查询图纸信息
     *
     * @param req 请求信息
     * @param response response
     * @return 图纸信息
     */
    @PostMapping("draw")
    @LogAnnotation(value = "查询图纸信息", business = LogBusinessConstants.MATERIAL_RESUME, operateType = LogOperateConstants.OPERATE_QUERY)
    public void queryDrawInfo(@RequestBody BaseDeleteReq req, HttpServletResponse response) {
        materialResumeService.queryDrawInfo(req.getId(),response);
//        BaseResp resp = new BaseResp();
//        resp.setRetMessage("查询图纸信息成功");
//        resp.setDataMap(dataMap);
//        return resp;
    }

    /**
     * 查询ECN文件信息
     *
     * @param req      请求信息
     * @param response response
     * @return ECN信息
     */
    @PostMapping("ecn")
    @LogAnnotation(value = "查询ECN文件信息", business = LogBusinessConstants.MATERIAL_RESUME, operateType = LogOperateConstants.OPERATE_QUERY)
    public void queryECNInfo(@RequestBody BaseDeleteReq req, HttpServletResponse response) {
        materialResumeService.queryECNInfo(req.getId(), response);
//        BaseResp resp = new BaseResp();
//        resp.setRetMessage("查询ECN文件信息成功");
//        return resp;
    }

    /**
     * 导出物料履历信息
     *
     * @param req      请求信息
     * @param response response
     * @return 导出数据
     */
    @PostMapping("export")
    @LogAnnotation(value = "导出物料履历信息", business = LogBusinessConstants.MATERIAL_RESUME, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportMaterialResume(@RequestBody QueryMaterialResumeReq req, HttpServletResponse response) {
        materialResumeService.exportMaterialResume(req.getMaterial(), req.getRegion(), req.getStartTime(),response);
    }
}
